<?php

namespace common\models;

use Yii;
use common\behaviors\CodeBehavior;
use \common\models\base\GenerateRecords as BaseGenerateRecords;

/**
 * This is the model class for table "generate_records".
 */
class GenerateRecords extends BaseGenerateRecords
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return array_replace_recursive(parent::rules(),
	    [
            [['character_id'], 'required'],
            [['created_at', 'updated_at', 'deleted_at'], 'safe'],
            [['id', 'character_id', 'created_by', 'updated_by', 'deleted_by'], 'string', 'max' => 32],
            [['quantity'], 'string', 'max' => 45],
        ]);
    }

    public function behaviors()
    {
        return array_merge(parent::behaviors(),[

            //生成邀请码的behavior
            'code' => [
                'class' => CodeBehavior::className(),
            ],


        ]);
    }

    protected $_charName;

    public function getCharName()
    {
        if (!$this->_charName){
            $this->_charName = $this->character?$this->character->name:'';
        }
        return $this->_charName;
    }
	
}
